package com.nali.dal.statement.query;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.nali.dal.expression.PropertyExpression;
import com.nali.dal.expression.query.Criteria;

public class OriginColumn implements ColumnUnitConfig {
	private static class OriginColumnUnit implements ColumnUnit {
		private final String alias;
		private final String column;
		public OriginColumnUnit(String alias, String column) {
			super();
			this.alias = alias;
			this.column = column;
		}

		@Override
		public String getName() {
			return alias;
		}

		@Override
		public Object getColumnValue(Map<String, Object> lineDatas) {
			return lineDatas.get(column);
		}
	}

	private ColumnUnit columnUnit;
	private List<String> columns;
	private List<PropertyExpression<Criteria>> columnCriterias;

	@SuppressWarnings("unchecked")
	public OriginColumn(String alias, String column) {
		columnCriterias = Arrays.asList(new PropertyExpression<Criteria>(column, Criteria.select));
		columns = Arrays.asList(column);
		columnUnit = new OriginColumnUnit(alias, column);
	}

	@Override
	public List<PropertyExpression<Criteria>> getColumnCriterias() {
		return columnCriterias;
	}

	@Override
	public ColumnUnit getColumnUnit() {
		return this.columnUnit;
	}

	@Override
	public List<String> getColumns() {
		return columns;
	}

}
